from time import sleep

from selenium import webdriver

# 打开网页
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

driver = webdriver.Chrome()
driver.get('http://192.168.124.48:80/admin')
driver.implicitly_wait(10)
# 登录
driver.find_element(By.NAME, 'username').send_keys('admin')
driver.find_element(By.NAME, 'password').send_keys('123456')
driver.find_element(By.NAME, 'vertify').send_keys('8888')
driver.find_element(By.NAME, 'submit').click()

# 点击商城---促销---抢购管理
driver.find_element_by_xpath('/html/body/div[1]/div[4]/ul/li[2]').click()
driver.find_element_by_xpath('//*[@id="admincpNavTabs_shop"]/dl[3]/dt/a').click()
iframe = driver.find_element_by_id("workspace")
# 切换句柄
driver.switch_to.frame('workspace')
driver.find_element_by_class_name('add').click()
sleep(2)
# 创建添加活动
driver.find_element_by_id('title').send_keys('赔钱大甩卖')

driver.find_element_by_id('select_goods_button').click()
iframe1=driver.find_element_by_id("layui-layer-iframe1")
driver.switch_to.frame("iframe1")
sleep(2)
driver.find_element_by_xpath('//*[@id="flexigrid"]/table/tbody/tr[2]/td[1]/div/input').click()
driver.find_element_by_xpath('//*[@id="flexigrid"]/table/tbody/tr[3]/td[1]/div/input').click()
driver.find_element_by_xpath('/html/body/div/div/div[5]/a').click()
sleep(2)
# iframe1 = driver.find_element_by_id("workspace")
# driver.switch_to.frame(iframe1)
driver.find_element_by_name('price').send_keys('30')
driver.find_element_by_name('goods_num').send_keys('1')
driver.find_element_by_name('buy_limit').send_keys('30')
driver.find_element_by_name('start_time').click()
driver.find_element_by_name('end_time').click()

sleep(2)
driver.close()

